<?php
/**
 * Created by JetBrains PhpStorm.
 * User: scala
 * Date: 12-10-23
 * Time: 下午2:01
 * To change this template use File | Settings | File Templates.
 */
class MessageAction extends Action
{

    function index(){
        import("ORG.Util.Page");// 导入分页类
        $message= D("Message");
        $count=$message->count();
        $Page= new Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfigArray(array('header'=>'条留言','prev'=>'<input type="button" value="<<">','next'=>'<input type="button" value=">>">','first'=>'首页','last'=>'尾页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页   %first% %prePage% %upPage%   <span style="color: red;">%linkPage%</span>   %downPage% %nextPage% %end%'));
        $show=$Page->show();//分页显示输出
        $messageList=$message->limit($Page->firstRow.",".$Page->listRows)->order("createtime desc")->select();
        $reply=M("MessageReply");
        $map['messageid']  = array();
        for($i=0;$i<count($messageList);$i++){
            $map['messageid'][]=array("eq",$messageList[$i]["id"]) ;
        }
        $map['messageid'][]="or";

        $replyList=$reply->where($map)->order("createtime desc")->select();
        $this->assign("messageList",$messageList);
        $this->assign("replyList",$replyList);
        $this->assign('page',$show);// 赋值分页输出


        $article=M("StaffArticle");
        $user=M("User");
        $centlist=$article->limit('0,3')->order("createtime desc")->select();
        $userList=$user->select();
        $this->assign("centlist",$centlist);
        $this->assign("userList",$userList);
        $this->display();
    }

    function insert(){
        $message=D("Message");
        if($message->create()){
            $message->add();
            echo '1';
        }else{
            echo '2';
        }
    }
    function aticon(){
        $this->redirect("Message/index");
    }

}
